package com.ruoyi.jeeplus.modules.screen.frontdesk.screen_workstatus.controller;

import com.ruoyi.jeeplus.modules.screen.frontdesk.screen_PV.mapper.FrontdeskScreenPVMapper;
import com.ruoyi.jeeplus.modules.screen.frontdesk.screen_charge.domain.Frontdesk_screen_chargeNew;
import com.ruoyi.jeeplus.modules.screen.frontdesk.screen_charge.service.impl.Frontdesk_screen_chargeServiceImpl;
import com.ruoyi.jeeplus.modules.screen.frontdesk.screen_workstatus.domain.Frontdesk_screen_workstatus;
import com.ruoyi.jeeplus.modules.screen.frontdesk.screen_workstatus.mapper.Frontdesk_screen_workstatusMapper;
import com.ruoyi.jeeplus.modules.screen.frontdesk.screen_workstatus.service.impl.Frontdesk_screen_workstatusImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 刘奥旸
 * @version 1.0
 */
@RestController
public class Frontdesk_screen_workstatusController {

    @Autowired
    Frontdesk_screen_workstatusMapper frontdeskScreenWorkstatusMapper;
    @Autowired
    Frontdesk_screen_workstatusImpl frontdeskScreenWorkstatus;
    @Autowired
    FrontdeskScreenPVMapper frontdeskScreenPVMapper;
    @GetMapping(value = "/lay/workstatus")
    public int a32(@RequestParam int id,@RequestParam int date){
        int using = frontdeskScreenWorkstatus.using(id, date);
        return using;
    }
    @GetMapping(value = "/lay/two_workstatus")
    public Map<String, Object> abc(@RequestParam String id){
        int region_id;
        // 正则表达式判断 id 是否是数字
        // 正则表达式判断 id 是否是数字
        // 正则表达式判断 id 是否是数字
        if (!id.matches("^[0-9]+$")) {
            // 如果 id 不是数字，执行数字相关的逻辑
            region_id = frontdeskScreenPVMapper.getIdByName(id);

        }else {
            region_id = Integer.parseInt(id); // 转换为 int
        }

        int all = frontdeskScreenWorkstatus.using(region_id, 0);
        int year = frontdeskScreenWorkstatus.using(region_id, 1);
        int month = frontdeskScreenWorkstatus.using(region_id, 2);
        int day = frontdeskScreenWorkstatus.using(region_id, 3);

        double year_ratio = 0;
        double month_ratio = 0;
        double day_ratio = 0;
        if (all != 0) { // 避免除以零
            year_ratio = (double) year / all * 100; // 转换为 double
            month_ratio = (double) month / all * 100; // 月占比
            day_ratio = (double) day / all * 100; // 日占比
            // year_ratio 现在是一个正确的百分比
        }
        Map<String, Object> kvMap = new HashMap<>();
        kvMap.put("all",all);
        kvMap.put("year",year);
        kvMap.put("month",month);
        kvMap.put("day",day);
        kvMap.put("year_ratio", year_ratio);
        kvMap.put("month_ratio", month_ratio);
        kvMap.put("day_ratio",day_ratio);
        return kvMap;
    }
    @GetMapping(value = "/lay/four_workstatus")
    public Map<String, Object> abc_four(@RequestParam String id){
        int region_id;
        // 正则表达式判断 id 是否是数字
        // 正则表达式判断 id 是否是数字
        // 正则表达式判断 id 是否是数字
        if (!id.matches("^[0-9]+$")) {
            // 如果 id 不是数字，执行数字相关的逻辑
            region_id = frontdeskScreenPVMapper.getIdByName(id);

        }else {
            region_id = Integer.parseInt(id); // 转换为 int
        }

        int all = frontdeskScreenWorkstatus.four_using(region_id, 0);
        int year = frontdeskScreenWorkstatus.four_using(region_id, 1);
        int month = frontdeskScreenWorkstatus.four_using(region_id, 2);
        int day = frontdeskScreenWorkstatus.four_using(region_id, 3);

        double year_ratio = 0;
        double month_ratio = 0;
        double day_ratio = 0;
        if (all != 0) { // 避免除以零
            year_ratio = (double) year / all * 100; // 转换为 double
            month_ratio = (double) month / all * 100; // 月占比
            day_ratio = (double) day / all * 100; // 日占比
            // year_ratio 现在是一个正确的百分比
        }
        Map<String, Object> kvMap = new HashMap<>();
        kvMap.put("all",all);
        kvMap.put("year",year);
        kvMap.put("month",month);
        kvMap.put("day",day);
        kvMap.put("year_ratio", year_ratio);
        kvMap.put("month_ratio", month_ratio);
        kvMap.put("day_ratio",day_ratio);
        return kvMap;
    }
}
